package isae.c2.android.depense;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.TextView;
import isae.c2.android.depense.DB.TransactionDBAdapter;

public class Main extends Activity {
    private TransactionDBAdapter mDbHelper;
    private float IncomeSum;
    private float OutcomeSum;
    private float Total;
    /** On fait appel a cette page quand l'activite est creee. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
    
        mDbHelper = new TransactionDBAdapter(this);
        mDbHelper.open();
        
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);        
                
         //Ce bouton nous permet de creer une nouvelle transaction
        Button b1 = (Button) findViewById(R.id.button2);
        b1.setOnClickListener(new OnClickListener() {
			
           public void onClick(View v) {
              startActivity(new Intent(Main.this, New_Transaction.class));
           }
        });
        
        Button b2 = (Button) findViewById(R.id.button3);
        b2.setOnClickListener(new OnClickListener() {
            
            public void onClick(View v) {
                // TODO Auto-generated method stub
                startActivity(new Intent(Main.this, list_transactions.class));
            }
        });
        
        // Ce bouton me mene a la page create_category
        Button b = (Button) findViewById(R.id.button1);
        b.setOnClickListener(new OnClickListener() {
            
            public void onClick(View v) {
                // Auto-générés method sub
                startActivity(new Intent(Main.this, list_category.class));
            }
        });
        // Mettre a jour les donnees
        fillData();
    }
    
    @Override
    protected void onStart() {
        super.onStart();
        fillData();

    }
    /* Afficher la somme des revenus, la somme des depenses et la balance */
    private void fillData() {
        
        TextView bal = (TextView) findViewById(R.id.bal);
        TextView balIncome = (TextView) findViewById(R.id.income);
        TextView balOutcome = (TextView) findViewById(R.id.outcome);
        
        IncomeSum = mDbHelper.getIncome();
        balIncome.setText    ("Somme des revenus:           "+ IncomeSum);
        
        OutcomeSum = mDbHelper.getOutcome();
        balOutcome.setText    ("Somme des dépenses:          "+ OutcomeSum);
        
        Total = IncomeSum-OutcomeSum;
        
        bal.setText            ("Votre balance est:                "+ Total);
    }
    
}